﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Teigha.Core
{
	public class OdGsDevice : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdGsDevice(IntPtr cPtr, bool cMemoryOwn) : base(GlobalsPINVOKE.OdGsDevice_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdGsDevice obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdGsDevice()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							GlobalsPINVOKE.delete_OdGsDevice(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdGsDevice cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdGsDevice_cast(OdRxObject.getCPtr(pObj));
			OdGsDevice result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdGsDevice)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdGsDevice)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdGsDevice)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdGsDevice_desc(), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdGsDevice_isA(this.swigCPtr), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdGsDevice_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdGsDevice createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdGsDevice_createObject();
			OdGsDevice result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdGsDevice)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdGsDevice)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdGsDevice)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdRxDictionary properties()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdGsDevice_properties(this.swigCPtr);
			OdRxDictionary result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdRxDictionary)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdRxDictionary)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdRxDictionary)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdGiContext userGiContext()
		{
			OdGiContext result = (OdGiContext)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdGsDevice_userGiContext(this.swigCPtr), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void setUserGiContext(OdGiContext pUserGiContext)
		{
			GlobalsPINVOKE.OdGsDevice_setUserGiContext(this.swigCPtr, OdGiContext.getCPtr(pUserGiContext));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void invalidate()
		{
			GlobalsPINVOKE.OdGsDevice_invalidate__SWIG_0(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void invalidate(OdGsDCRect screenRect)
		{
			GlobalsPINVOKE.OdGsDevice_invalidate__SWIG_1(this.swigCPtr, OdGsDCRect.getCPtr(screenRect));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual bool isValid()
		{
			bool result = GlobalsPINVOKE.OdGsDevice_isValid(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void update(OdGsDCRect pUpdatedRect)
		{
			GlobalsPINVOKE.OdGsDevice_update__SWIG_0(this.swigCPtr, OdGsDCRect.getCPtr(pUpdatedRect));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void update()
		{
			GlobalsPINVOKE.OdGsDevice_update__SWIG_1(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void onSize(OdGsDCRect outputRect)
		{
			GlobalsPINVOKE.OdGsDevice_onSize__SWIG_0(this.swigCPtr, OdGsDCRect.getCPtr(outputRect));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void onSize(OdGsDCRectDouble outputRect)
		{
			GlobalsPINVOKE.OdGsDevice_onSize__SWIG_1(this.swigCPtr, OdGsDCRectDouble.getCPtr(outputRect));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void onRealizeForegroundPalette()
		{
			GlobalsPINVOKE.OdGsDevice_onRealizeForegroundPalette(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void onRealizeBackgroundPalette()
		{
			GlobalsPINVOKE.OdGsDevice_onRealizeBackgroundPalette(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void onDisplayChange(int bitsPerPixel, int xPixels, int yPixels)
		{
			GlobalsPINVOKE.OdGsDevice_onDisplayChange(this.swigCPtr, bitsPerPixel, xPixels, yPixels);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual OdGsView createView(OdGsClientViewInfo pViewInfo, bool enableLayerVisibilityPerView)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdGsDevice_createView__SWIG_0(this.swigCPtr, OdGsClientViewInfo.getCPtr(pViewInfo), enableLayerVisibilityPerView);
			OdGsView result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdGsView)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdGsView)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdGsView)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdGsView createView(OdGsClientViewInfo pViewInfo)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdGsDevice_createView__SWIG_1(this.swigCPtr, OdGsClientViewInfo.getCPtr(pViewInfo));
			OdGsView result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdGsView)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdGsView)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdGsView)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdGsView createView()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdGsDevice_createView__SWIG_2(this.swigCPtr);
			OdGsView result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdGsView)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdGsView)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdGsView)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void addView(OdGsView pView)
		{
			GlobalsPINVOKE.OdGsDevice_addView(this.swigCPtr, OdGsView.getCPtr(pView));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual OdGsModel createModel()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdGsDevice_createModel(this.swigCPtr);
			OdGsModel result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdGsModel)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdGsModel)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdGsModel)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool isModelCompatible(OdGsModel pModel)
		{
			bool result = GlobalsPINVOKE.OdGsDevice_isModelCompatible(this.swigCPtr, OdGsModel.getCPtr(pModel));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool saveDeviceState(SWIGTYPE_p_OdGsFiler pFiler)
		{
			bool result = GlobalsPINVOKE.OdGsDevice_saveDeviceState(this.swigCPtr, SWIGTYPE_p_OdGsFiler.getCPtr(pFiler));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool loadDeviceState(SWIGTYPE_p_OdGsFiler pFiler)
		{
			bool result = GlobalsPINVOKE.OdGsDevice_loadDeviceState(this.swigCPtr, SWIGTYPE_p_OdGsFiler.getCPtr(pFiler));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void insertView(int viewIndex, OdGsView pView)
		{
			GlobalsPINVOKE.OdGsDevice_insertView(this.swigCPtr, viewIndex, OdGsView.getCPtr(pView));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual bool eraseView(OdGsView pView)
		{
			bool result = GlobalsPINVOKE.OdGsDevice_eraseView__SWIG_0(this.swigCPtr, OdGsView.getCPtr(pView));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool eraseView(int viewIndex)
		{
			bool result = GlobalsPINVOKE.OdGsDevice_eraseView__SWIG_1(this.swigCPtr, viewIndex);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void eraseAllViews()
		{
			GlobalsPINVOKE.OdGsDevice_eraseAllViews(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual int numViews()
		{
			int result = GlobalsPINVOKE.OdGsDevice_numViews(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdGsView viewAt(int viewIndex)
		{
			OdGsView result = (OdGsView)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdGsDevice_viewAt(this.swigCPtr, viewIndex), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool setBackgroundColor(uint backgroundColor)
		{
			bool result = GlobalsPINVOKE.OdGsDevice_setBackgroundColor(this.swigCPtr, backgroundColor);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual uint getBackgroundColor()
		{
			uint result = GlobalsPINVOKE.OdGsDevice_getBackgroundColor(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void setLogicalPalette(uint[] logicalPalette, int numColors)
		{
			GlobalsPINVOKE.OdGsDevice_setLogicalPalette(this.swigCPtr, logicalPalette, numColors);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void getSnapShot(out OdGiRasterImage pImage, OdGsDCRect region)
		{
			IntPtr zero = IntPtr.Zero;
			try
			{
				GlobalsPINVOKE.OdGsDevice_getSnapShot(this.swigCPtr, out zero, OdGsDCRect.getCPtr(region));
				if (GlobalsPINVOKE.SWIGPendingException.Pending)
				{
					throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
				}
			}
			finally
			{
				pImage = (OdGiRasterImage)Teigha.Core.Helpers.odrxCreateObjectInternal(zero, true);
			}
		}

		private object locker = new object();

		private HandleRef swigCPtr;
	}
}
